The gdk-pixbuf Library | |||
---|---|---|---|
<<< Previous Page | Home | Up | Next Page >>> |
The basic principle in gdk-pixbuf is that when you obtain a new GdkPixbuf structure, it is created with an initial reference count of 1. When another part of the program wants to keep a reference to the pixbuf, it should call gdk_pixbuf_ref(); this will increase the reference count by 1. When some part of the program does not need to keep a reference to a pixbuf anymore and wants to release the pixbuf, it should call gdk_pixbuf_unref(); this will decrease the reference count by 1. When the reference count drops to zero, the pixbuf gets destroyed or finalized and its memory is freed.
For applications that need to implement a cache of loaded images, gdk-pixbuf provides a way to hook to the last unreference operation of a pixbuf; instead of finalizing the pixbuf, the user-installed hook can decide to keep it around in a cache instead.
Finally, gdk-pixbuf does not provide a cache of rendered pixmaps. This is unnecessary for most applications, since the scaling and rendering functions are quite fast and applications may need to use subtly different values each time they call these functions, for example, to take into account dithering and zooming offsets.
Most applications will simply need to call gdk_pixbuf_ref() when they want to keep an extra reference to a pixbuf, and then gdk_pixbuf_unref() when they are done with it.
<<< Previous Page | Home | Up | Next Page >>> |
Porting applications from Imlib to gdk-pixbuf | Converting Applications to gdk-pixbuf |